package com.aaa.java07;

import java.time.Duration;
import java.time.LocalDateTime;

/**
 * @author ：Teacher陈（86521760@qq.com）
 * @date ：Created in 2022/7/8 15:03
 * @description：
 * @modified By：
 * @version:
 */
public class EmpNew {
    int id;
    String name;
    LocalDateTime checkInTime;
    LocalDateTime checkOutTime;

    public EmpNew() {
    }

    public EmpNew(int id, String name, LocalDateTime checkInTime, LocalDateTime checkOutTime) {
        this.id = id;
        this.name = name;
        this.checkInTime = checkInTime;
        this.checkOutTime = checkOutTime;
    }

    /**
     * @create by: Teacher陈（86521760@qq.com）
     * @description: 获取工作时间
     * @create time: 2022/7/8 15:04
     * @param
     * @return java.lang.String
     */
    public String  getWorkTime(){
        Duration between = Duration.between(checkInTime, checkOutTime);
        //获取了工作的秒数
        long seconds = between.getSeconds();
        long hourSum=seconds/60/60;
        long minSum=seconds/60%60;
        long secondSum=seconds%60;

        return hourSum+"小时"+minSum+"分钟"+secondSum+"秒";
    }

    public static void main(String[] args) {
        LocalDateTime checkInTime = LocalDateTime.of(2022, 7, 8, 8, 20, 12);
        LocalDateTime checkOutTime =  LocalDateTime.of(2022,7,8,21,30,22);
        EmpNew emp = new EmpNew(12345,"晋升",checkInTime,checkOutTime);
        String workTime = emp.getWorkTime();
        System.out.println(workTime);
    }

}
